#include <iostream>

//defines for game loop states
#define GAME_INIT 0// the game is initializing
#define GAME_MENU 1//the game is in the menu mode
#define GAME_SARTING 2//the game is about to run
#define GAME_RUN 3 //the game is now running
#define GAME_RESTART 4//the game is going to restart
#define GAME_EXIT 5// the game is exiting

//game globals
int game_state = GAME_INIT;// srart off in this state
int error = 0;//used to send crrors back to OS

void Init();
int Menu();
void Setup_For_Run();
void Clear();
void Get_Input();
void Do_Logic();
void Render_Frame();
void Wait();
void Fixup();
void Release_And_Cleanup();

int main() {
	//implementation of main game loop
	while (game_state != GAME_EXIT) {
		//what state is game loop in
		switch (game_state) {
		case GAME_INIT://the game is initializing
		{
			//allocate all memory and resources
			Init();
			//move to men state
			game_state = GAME_MENU;
		}
			break;
		case GAME_MENU://the game is in the menu mode
		{
			//call the main menu function and let it switch states
			game_state = Menu();
			//note:we could force a RUN state here
		}
		case GAME_SARTING://the game is about to run
		{
			// this state is optional, but usually used to
			//set things up right before the game is run
			//you might do a little more housekeeping here
			Setup_For_Run();
			//switch to run state
			game_state = GAME_RUN;
		}
		break;
		case GAME_RUN://the game is now running
		{
			// this section contains the entire game logic loop
			// clear the display
			Clear();
			// get the input
			Get_Input();
			//perlorm logic and ai
			Do_Logic();
			//display the next frame of animation
			Render_Frame();
			//synchronize the display
			Wait();
			//the only way that state can be changed is
			// thru user interaction in the
			//input section or by maybe losing the game.
		}
		break;
		case GAME_RESTART://the game is restarting
		{
			//this section is acleanup state used to
			//fix up any loose ends before
			//running again
			Fixup();
			//switch states back to the menu
			game_state = GAME_MENU;
		}
		break;
		case GAME_EXIT://the game is exiting
		{
			// if the game is in this state then
			// it's time to bail,kill everything
			// and cross your fingers
			Release_And_Cleanup();
			// set the error word to whatever
			error = 0;
			//note:we don't have to switch states
			//since we are already in this state
			//on the next loop ireration the code
			//will fall out of the main while and
			//exit back to the 0s
		}
		break;
		default:
			break;
		}// end switch
	}// end while

	return 0;
}